package com.jsj.service.impl;

import com.jsj.dao.SiminfoDao;
import com.jsj.dao.StudentDao;
import com.jsj.dao.SubmissionDao;
import com.jsj.domain.Siminfo;
import com.jsj.domain.Submission;
import com.jsj.domain.vo.ProblemSubmissionVo;
import com.jsj.service.ISubmissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SubmissionServiceImpl implements ISubmissionService {
    @Autowired
    private SubmissionDao submissionDao;
    @Autowired
    private StudentDao studentDao;
    @Autowired
    private SiminfoDao siminfoDao;

    @Override
    public List<ProblemSubmissionVo> querySubmissionByProblemId(int topicId, int problemId) {
        List<ProblemSubmissionVo> problemSubmissionVos = submissionDao.querySubmissionByProblemId(topicId, problemId);
        Siminfo siminfo;
        if (problemSubmissionVos != null) {
            for (ProblemSubmissionVo problemSubmissionVo : problemSubmissionVos) {
                siminfo = siminfoDao.querySiminfo(problemSubmissionVo.getId());
                problemSubmissionVo.setSimilarity(siminfo.getSimilarity());
                problemSubmissionVo.setTargetUserName(siminfo.getTargetId());
                problemSubmissionVo.setSourceNickName(studentDao.queryByUserName(problemSubmissionVo.getSourceUserName()).getNickName());
                problemSubmissionVo.setTargetNickName(studentDao.queryByUserName(problemSubmissionVo.getTargetUserName()).getNickName());
            }
        }
        return problemSubmissionVos;
    }

    @Override
    public Submission querySubmission(long id) {
        return submissionDao.querySubmission(id);
    }

    @Override
    public Integer insertSubmission(Submission submission) {
        return submissionDao.insertSubmission(submission);
    }

    @Override
    public Integer deleteSubmission(long id) {
        return submissionDao.deleteSubmission(id);
    }
}
